<template>
  <div class="dashboard">
    <el-row :gutter="20">
      <el-col :span="6">
        <el-card class="data-card">
          <template #header>
            <div class="card-header">
              <span>总器材数量</span>
              <el-icon><Tools /></el-icon>
            </div>
          </template>
          <div class="card-value">{{ statistics.totalEquipment }}</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="data-card">
          <template #header>
            <div class="card-header">
              <span>借出器材</span>
              <el-icon><Box /></el-icon>
            </div>
          </template>
          <div class="card-value">{{ statistics.borrowedEquipment }}</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="data-card">
          <template #header>
            <div class="card-header">
              <span>待审批申请</span>
              <el-icon><Document /></el-icon>
            </div>
          </template>
          <div class="card-value">{{ statistics.pendingApprovals }}</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="data-card">
          <template #header>
            <div class="card-header">
              <span>维修中器材</span>
              <el-icon><Setting /></el-icon>
            </div>
          </template>
          <div class="card-value">{{ statistics.underRepair }}</div>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="20" class="charts-row">
      <el-col :span="12">
        <el-card class="chart-card">
          <template #header>
            <div class="card-header">
              <span>近期借用趋势</span>
            </div>
          </template>
          <div class="chart-container">
            <el-empty v-if="!hasData" description="暂无数据" />
            <!-- 这里可以添加图表组件 -->
          </div>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card class="chart-card">
          <template #header>
            <div class="card-header">
              <span>器材类型分布</span>
            </div>
          </template>
          <div class="chart-container">
            <el-empty v-if="!hasData" description="暂无数据" />
            <!-- 这里可以添加图表组件 -->
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-card class="recent-activities">
      <template #header>
        <div class="card-header">
          <span>最近活动</span>
        </div>
      </template>
      <el-timeline>
        <el-timeline-item
          v-for="activity in recentActivities"
          :key="activity.id"
          :timestamp="activity.time"
          :type="activity.type"
        >
          {{ activity.content }}
        </el-timeline-item>
      </el-timeline>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { Tools, Box, Document, Setting } from '@element-plus/icons-vue'

const statistics = ref({
  totalEquipment: 156,
  borrowedEquipment: 45,
  pendingApprovals: 12,
  underRepair: 8
})

const hasData = ref(true)

const recentActivities = ref([
  {
    id: 1,
    content: '张三借用了显微镜',
    time: '2024-12-11 10:20',
    type: 'primary'
  },
  {
    id: 2,
    content: '李四归还了烧杯',
    time: '2024-12-11 09:15',
    type: 'success'
  },
  {
    id: 3,
    content: '新增了5台显微镜',
    time: '2024-12-11 08:30',
    type: 'info'
  }
])
</script>

<style scoped>
.dashboard {
  padding: 20px;
}

.data-card {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-value {
  font-size: 24px;
  font-weight: bold;
  color: #409EFF;
  text-align: center;
  padding: 10px 0;
}

.charts-row {
  margin-bottom: 20px;
}

.chart-card {
  height: 300px;
}

.chart-container {
  height: 250px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.recent-activities {
  margin-top: 20px;
}
</style>

